package com.technoorbit.vbreakup;


import java.util.ArrayList;


import android.content.Context;
import android.content.res.TypedArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class CustomListAddapter extends ArrayAdapter<CustomList> {

	private LayoutInflater mInflater;
	
	private TypedArray mIcons;
	@SuppressWarnings("unused")
	private ArrayList<CustomList> mItems;
	private int mViewResourceId;
	
	public CustomListAddapter(Context ctx, int viewResourceId, ArrayList<CustomList> items, TypedArray icons) {
		super(ctx, viewResourceId, items);
		
		mInflater = (LayoutInflater)ctx.getSystemService(
				Context.LAYOUT_INFLATER_SERVICE);
		this.mItems=items;
		mIcons = icons;
		mViewResourceId = viewResourceId;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		convertView = mInflater.inflate(mViewResourceId, null);
		try{
		ImageView iv = (ImageView)convertView.findViewById(R.id.imgItem);
		iv.setImageDrawable(mIcons.getDrawable(position));
		CustomList cList = getItem(position);
		
		TextView tv = (TextView)convertView.findViewById(R.id.textItem);
		tv.setText(cList.getItem());
		
		TextView tvID = (TextView)convertView.findViewById(R.id.txtCustomID);
		String id=Integer.toString(cList.getID());
		tvID.setText(id);
				
		
		TextView tvSubItem = (TextView)convertView.findViewById(R.id.textSubItem);
		tvSubItem.setText(cList.getSubItem());
		
		
		return convertView;
		}
		catch (Exception e) {
			e.printStackTrace();
		return null;
		}
	}


}
